package com.spider.demo3stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

public class StreamDemo4 {
    public static void main(String[] args) {
        //目标：掌握stream流的终结方法。
        List<Teacher> teachers = new ArrayList<>();
        teachers.add(new Teacher("张小明", 25, 8000));
        teachers.add(new Teacher("李小红", 30, 12000));
        teachers.add(new Teacher("王小军", 28, 10000));
        teachers.add(new Teacher("赵小丽", 35, 15000));
        teachers.stream().filter(t -> t.getSalary() > 10000).forEach(System.out::println);
        System.out.println("------------------------------------------------------------------------");
        long count = teachers.stream().filter(t -> t.getSalary() > 10000).count();
        System.out.println(count);
        System.out.println("------------------------------------------------------------------------");
        Optional<Teacher> max = teachers.stream().max((t1, t2) -> Double.compare(t1.getSalary(), t2.getSalary()));
        System.out.println(max.get());
        System.out.println("------------------------------------------------------------------------");
        Optional<Teacher> min = teachers.stream().min((t1, t2) -> Double.compare(t1.getSalary(), t2.getSalary()));
        System.out.println(min.get());
        System.out.println("------------------------------------------------------------------------");
    }
}
